package com.adams.app.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

import android.database.Cursor;

import com.adams.app.dao.AttractionDataHelper;
import com.google.gson.Gson;

public class Attractions extends BaseType implements Serializable {

	private static final long serialVersionUID = 1L;

	private static final HashMap<Long, Attractions> CACHE = new HashMap<Long, Attractions>();

	private Long id;
	private String name;
	private String address;
	private String tel;
	private String intro;
	private String time;
	private String price;
	private Integer times;
	private String urlPic;
	private String visitTime;
	private String evaluate;

	public String getUrlPic() {
		return urlPic;
	}

	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getAddress() {
		return address;
	}

	public String getTel() {
		return tel;
	}

	public String getIntro() {
		return intro;
	}

	public String getTime() {
		return time;
	}

	public String getPrice() {
		return price;
	}

	public Integer getTimes() {
		return times;
	}

	public String getVisitTime() {
		return visitTime;
	}

	public String getEvaluate() {
		return evaluate;
	}

	private static void addToCache(Attractions attractions) {
		CACHE.put(attractions.getId(), attractions);
	}

	private static Attractions getFromCache(long id) {
		return CACHE.get(id);
	}

	public static Attractions fromJson(String json) {
		return new Gson().fromJson(json, Attractions.class);
	}

	public static Attractions fromCursor(Cursor cursor) {
		long id = cursor.getLong(cursor
				.getColumnIndex(AttractionDataHelper.AttractionsDBInfo._ID));
		Attractions attractions = getFromCache(id);
		if (attractions != null) {
			return attractions;
		}
		attractions = new Gson().fromJson(cursor.getString(cursor
				.getColumnIndex(AttractionDataHelper.AttractionsDBInfo.JSON)),
				Attractions.class);
		addToCache(attractions);
		return attractions;
	}

	public static class AttractionRequestData {

		private ArrayList<Attractions> attractions;

		public ArrayList<Attractions> getAttractions() {
			return attractions;
		}
	}

}
